package com.ctshk.rpc.order.hotel.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.*;
import com.ctshk.common.enums.Currency;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.SnowflakeIdWorker;
import com.ctshk.rpc.booking.req.system.airexpress.add.SupplierOrderSystemAirExpressAddReq;
import com.ctshk.rpc.booking.service.ISupplierOrderService;
import com.ctshk.rpc.hotel.dto.*;
import com.ctshk.rpc.hotel.req.*;
import com.ctshk.rpc.hotel.service.IHotelOrderService;
import com.ctshk.rpc.hotel.service.IHotelProductService;
import com.ctshk.rpc.hotel.service.IHotelService;
import com.ctshk.rpc.iotc.dto.OperateBankPreferenceQueryDTO;
import com.ctshk.rpc.iotc.req.OperateBankConformQueryReq;
import com.ctshk.rpc.iotc.req.OperateBankDeductReq;
import com.ctshk.rpc.iotc.service.IOperateBankPreferenceService;
import com.ctshk.rpc.order.hotel.entity.*;
import com.ctshk.rpc.order.hotel.mapper.*;
import com.ctshk.rpc.system.constants.Constants;
import com.ctshk.rpc.system.dto.MainDataCurrencyListDTO;
import com.ctshk.rpc.system.dto.MainDataCurrencyQueryDTO;
import com.ctshk.rpc.system.dto.SysDepartmentDTO;
import com.ctshk.rpc.system.dto.UserDTO;
import com.ctshk.rpc.system.dto.member.ContactQueryDTO;
import com.ctshk.rpc.system.req.MainDataCurrencyListReq;
import com.ctshk.rpc.system.req.MainDataCurrencyUpdateStatusReq;
import com.ctshk.rpc.system.req.crm.member.CrmMemberQueryReq;
import com.ctshk.rpc.system.service.*;
import com.github.houbb.heaven.util.util.CollectionUtil;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 酒店订单表 服务实现类
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-08
 */
@DubboService
public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderMapper, HotelOrder> implements IHotelOrderService {
    @Autowired
    private HotelOrderMapper hotelOrderMapper;
    @Autowired
    private HotelOrderTouristMapper hotelOrderTouristMapper;
    @DubboReference
    private IMainDataCurrencyService iMainDataCurrencyService;
    @Autowired
    private HotelOrderCollectionMapper hotelOrderCollectionMapper;
    @Autowired
    private HotelManualOrderMapper hotelManualOrderMapper;
    @Autowired
    private HotelOrderRefundMapper hotelOrderRefundMapper;
    @Autowired
    private HotelOrderReceiptMapper hotelOrderReceiptMapper;
    @DubboReference
    private IHotelService hotelService;
    @DubboReference
    private IHotelProductService hotelProductService;
    @DubboReference
    private ICrmMemberService crmMemberService;
    @DubboReference
    private IMainDataCurrencyService mainDataCurrencyService;
    @DubboReference
    private ISysUserService sysUserService;
    @DubboReference
    private ISysDepartmentService sysDepartmentService;
    @DubboReference
    private IOperateBankPreferenceService operateBankPreferenceService;
    @DubboReference
    private ISupplierOrderService supplierOrderService;

    @Override
    public Result submit(HotelOrderSaveReq hotelOrderSaveReq, TokenUser currentUser) {
        LocalDateTime nowLocalDateTime = LocalDateTime.now();
        LocalDate nowLocalDate = LocalDate.now();
        int touristNumber = hotelOrderSaveReq.getCustomerNum();
        Integer roomNumber = hotelOrderSaveReq.getRoomNumber();
        // 查询加幅后的价格，售卖类型，余票
        HotelIncreaseStrategyPriceQueryReq hotelIncreaseStrategyPriceQueryReq = new HotelIncreaseStrategyPriceQueryReq();
        hotelIncreaseStrategyPriceQueryReq.setHotelProductId(hotelOrderSaveReq.getHotelProductId());
        hotelIncreaseStrategyPriceQueryReq.setTouristNumber(touristNumber);
        hotelIncreaseStrategyPriceQueryReq.setUserId(currentUser.getId());
        if (hotelOrderSaveReq.getIsAgent() == 1) {//是否使用代理
            hotelIncreaseStrategyPriceQueryReq.setAgentId(hotelOrderSaveReq.getAgencyId());
        }
        HotelPriceRemainderDTO hotelPriceRemainderDTO = hotelProductService.selectSelfPriceRemainderAndLock(hotelIncreaseStrategyPriceQueryReq);

        HotelOrder hotelOrder = EntityUtil.copy(hotelOrderSaveReq, HotelOrder.class);
        //计算订单金额
        BigDecimal orderAmount;
        BigDecimal childrenPrice = null;
        BigDecimal adultPrice = hotelPriceRemainderDTO.getPrice();
        BigDecimal adultPriceTotal = adultPrice.multiply(new BigDecimal(roomNumber));
        orderAmount = adultPriceTotal;
        /**·
         * 根据总价计算应收金额，减去会员积分和优惠券
         */
        BigDecimal receivableAmount = buildReceivableAmount(hotelOrder, orderAmount);
        //获取机场快线订单编号
        hotelOrder.setOrderNumber(generatorOrderNumber(currentUser.getId(), nowLocalDateTime));
        // 计算付款到期时间,+30分钟
        hotelOrder.setPayExpireDate(nowLocalDateTime.plusMinutes(30)); //固定30分钟
        // 获取id
        Long id = SnowflakeIdWorker.nextId();
        // 获取计划汇率 并设置
        hotelOrder.setOrderAmount(hotelPriceRemainderDTO.getPrice());
//        hotelOrder.setCurrencyId(Currency.HKD.getCode());
//        hotelOrder.setAdultCostCurrency(Currency.HKD.getCurrency());
//        hotelOrder.setRate(BigDecimal.ONE);
        //
        hotelOrder.setId(id);
        hotelOrder.setOrderAmount(orderAmount);
        hotelOrder.setReceivableAmount(receivableAmount);
        hotelOrder.setNumber(touristNumber);
        hotelOrder.setOrderAmount(adultPrice);
        hotelOrder.setContactName(hotelOrder.getSurname() + hotelOrder.getName());
        hotelOrder.setPaymentStatus(OrderPaymentStatus.UN_PAYMENT.getCode()); //未付款
        hotelOrder.setScheduledStatus(null);
        hotelOrder.setCancelStatus(null);
        hotelOrder.setSalesmanId(currentUser.getId());
        hotelOrder.setSalesmanName(currentUser.getNickname());
        hotelOrder.setIsDeleted(IsDeletedCode.NO.getCode());
        hotelOrder.setCreateId(currentUser.getId());
        hotelOrder.setGmtCreate(nowLocalDateTime);
        hotelOrder.setModifiedId(currentUser.getId());
        hotelOrder.setGmtModified(nowLocalDateTime);
        if(hotelOrderSaveReq.getHotelOrderContactPersonInfo()!=null){
            hotelOrder.setSurname(hotelOrderSaveReq.getHotelOrderContactPersonInfo().getContactSurname());
            hotelOrder.setContactName(hotelOrderSaveReq.getHotelOrderContactPersonInfo().getContactName());
            hotelOrder.setContactEmail(hotelOrderSaveReq.getHotelOrderContactPersonInfo().getContactEmail());
            hotelOrder.setContactMobileAreaCodeId(hotelOrderSaveReq.getHotelOrderContactPersonInfo().getContactMobileAreaCodeId());
            hotelOrder.setContactMobileAreaCode(hotelOrderSaveReq.getHotelOrderContactPersonInfo().getContactMobileAreaCode());
        }
        hotelOrderMapper.insert(hotelOrder);
        //保存旅客信息
        if(CollectionUtil.isNotEmpty(hotelOrderSaveReq.getHotelOrderRoomCustomerInfoList())){
            for (int i = 0; i < hotelOrderSaveReq.getHotelOrderRoomCustomerInfoList().size(); i++) {
                HotelOrderRoomCustomerInfo hotelOrderRoomCustomerInfo = hotelOrderSaveReq.getHotelOrderRoomCustomerInfoList().get(i);
                HotelOrderTourist hotelOrderTourist = new HotelOrderTourist();
                hotelOrderTourist.setId(IdWorker.getId());
                hotelOrderTourist.setGmtModified(LocalDateTime.now());
                hotelOrderTourist.setCreateId(currentUser.getId());
                hotelOrderTourist.setGender(null);//不区分性别  默认0
                hotelOrderTourist.setIsDeleted(0);
                hotelOrderTourist.setModifiedId(currentUser.getId());
                hotelOrderTourist.setName(hotelOrderRoomCustomerInfo.getName());
                hotelOrderTourist.setOrderId(hotelOrder.getId());
                hotelOrderTourist.setSurname(hotelOrderRoomCustomerInfo.getSurName());
                hotelOrderTourist.setTouristName(hotelOrderRoomCustomerInfo.getSurName()+hotelOrderRoomCustomerInfo.getName());
                hotelOrderTourist.setTouristType("1");//1:成人，2：小童  自录入的时候不区分，API可能需要
                hotelOrderTourist.setGmtCreate(LocalDateTime.now());
                hotelOrderTouristMapper.insert(hotelOrderTourist);
            }
        }

        return Result.success(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result pay(Long id, List<HotelOrderCollectionReq> hotelOrderCollectionReqList, TokenUser currentUser) {
        HotelOrder hotelOrder = hotelOrderMapper.selectById(id);
        if (hotelOrder == null) {
            //订单不存在
            throw new BusinessException(SystemError.HOTEL_10031);
        }
        LocalDateTime nowLocalDateTime = LocalDateTime.now();
        if (nowLocalDateTime.isAfter(hotelOrder.getPayExpireDate())) {
            // 支付超时
            throw new BusinessException(SystemError.HOTEL_10078);
        }
        UserDTO userDTO = sysUserService.loadUserByParam(currentUser.getId(), 1);
        SysDepartmentDTO sysDepartmentDTO = sysDepartmentService.queryOne(userDTO.getDeptId());
        hotelOrder.setModifiedId(currentUser.getId());
        hotelOrder.setGmtModified(nowLocalDateTime);
        // 计算支付总金额和支付记录
        boolean useUnionpayDiscount = false;
        BigDecimal amountCountHKD = BigDecimal.ZERO;//订单金额(港币)=实收金额+积分抵扣+优惠券
        BigDecimal readyMoney = BigDecimal.ZERO;//实收金额(港币)
        List<HotelOrderCollection> hotelOrderCollectionList = EntityUtil.copyList(hotelOrderCollectionReqList, HotelOrderCollection.class);
        for (HotelOrderCollection hotelOrderCollection : hotelOrderCollectionList) {
            if (hotelOrderCollection.getCurrencyId() == null) {
                //币种不能为空
                throw new BusinessException(SystemError.HOTEL_10079);
            }
            // 获取对应汇率，计算支付金额
            MainDataCurrencyQueryDTO currencyQueryDTO = getExchangeRateByName(hotelOrderCollection.getCurrencyId());
            BigDecimal marketExchangeRate = currencyQueryDTO.getMarketExchangeRate();
            BigDecimal amountHKD;
            if (hotelOrderCollection.getIsUnionpayDiscount() == 1) {
                // 使用银联优惠
                if (hotelOrder.getUsingPoints() != null || hotelOrder.getCouponId() != null) {
                    //使用了会员积分或优惠券，无法使用银联优惠
                    throw new BusinessException(SystemError.HOTEL_10079);
                }
                useAmountByBankReference(hotelOrder, hotelOrderCollection, currentUser);
                amountHKD = hotelOrderCollection.getCollectionAmount();
                useUnionpayDiscount = true;
            } else {
                //CRM会员积分-计算加积分的金额，do something 哪些付款方式需要算加积分
                amountHKD = hotelOrderCollection.getCollectionAmount().multiply(marketExchangeRate);
                readyMoney = readyMoney.add(amountHKD);
            }
            amountCountHKD = amountCountHKD.add(amountHKD);
            String paymentNumber = generatorPaymentNumber(nowLocalDateTime);
            hotelOrderCollection.setId(SnowflakeIdWorker.nextId());
            hotelOrderCollection.setOrderId(id);
            hotelOrderCollection.setCollectionNumber(paymentNumber);
            hotelOrderCollection.setCurrency(currencyQueryDTO.getCurrencyCode());
            hotelOrderCollection.setStandardAmount(amountHKD);//本位币金额
            hotelOrderCollection.setStatus(OrderCollectionStatus.UN_REJECT.getCode());
            hotelOrderCollection.setSalerId(currentUser.getId());
            hotelOrderCollection.setSalerName(currentUser.getNickname());
            hotelOrderCollection.setIsDeleted(IsDeletedCode.NO.getCode());
            hotelOrderCollection.setCreateId(currentUser.getId());
            hotelOrderCollection.setGmtCreate(nowLocalDateTime);
            hotelOrderCollection.setModifiedId(currentUser.getId());
            hotelOrderCollection.setGmtModified(nowLocalDateTime);
        }
        // 校验应收价格
        checkAmount(amountCountHKD, hotelOrder.getReceivableAmount());
        /**
         * 港铁下单
         */
//        AirportExpressMTRDTO airportExpressMTRDTO = buildMtrAndSendCreateOrder(airportExpressOrder);
//        if (airportExpressMTRDTO == null || com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(airportExpressMTRDTO.getTicket())) {
//            //下单失败
//            airportExpressOrder.setScheduledStatus(OrderScheduledStatus.RESERVE_FAIL.getCode());
//            airportExpressOrderMapper.updateById(airportExpressOrder);
//            return Result.failed(SystemError.AIREXPRESS_ORDER_60017);
//        }
        /**
         * 上传二维码图片到阿里云
         */
//        List<UploadReq> uploadReqList = buildUploadReq(airportExpressOrder.getId(), airportExpressMTRDTO);
//        fileOSSService.upload(uploadReqList);
        /**
         * 港铁下单成功后
         * 1.减去使用的会员积分，增加消费的产生会员积分
         * 2.减去使用的优惠券(机场快线无优惠券业务)
         */
//        if (!useUnionpayDiscount) {
//            List<AirportExpressOrderCollection> airportExpressOrderCollectionThirdList = new ArrayList<>();
//            useAndUpdateCrmMemberPoints(airportExpressOrder, readyMoney, currentUser, airportExpressOrderCollectionThirdList);
//        }
        //机场快线车票信息列表
//        List<HotelOrderTourist> hotelOrderTouristList = new ArrayList<>();
//        airportExpressMTRDTO.getTicket().forEach(ticketMtrDto -> {
//            AirportExpressOrderTourist airportExpressOrderTourist = new AirportExpressOrderTourist();
//            airportExpressOrderTourist.setId(SnowflakeIdWorker.nextId());
//            airportExpressOrderTourist.setOrderId(id);
//            airportExpressOrderTourist.setThirdTicketNumber(ticketMtrDto.getTid());
//            airportExpressOrderTourist.setThirdTicketQrCode(ticketMtrDto.getQrcode());
//            String qrCodeUrl = Constants.FILE_HOST + ticketMtrDto.getFullName();
//            airportExpressOrderTourist.setThirdTicketQrCodeUrl(qrCodeUrl);
//            //设置旅客类型
//            if (ticketMtrDto.getProfile().equals("0")) {
//                airportExpressOrderTourist.setTouristType(1);
//            }
//            if (ticketMtrDto.getProfile().equals("3")) {
//                airportExpressOrderTourist.setTouristType(2);
//            }
//            airportExpressOrderTourist.setIsDeleted(IsDeletedCode.NO.getCode());
//            airportExpressOrderTourist.setCreateId(currentUser.getId());
//            airportExpressOrderTourist.setGmtCreate(nowLocalDateTime);
//            airportExpressOrderTourist.setModifiedId(currentUser.getId());
//            airportExpressOrderTourist.setGmtModified(nowLocalDateTime);
//            airportExpressOrderTouristList.add(airportExpressOrderTourist);
//        });

        //新增收据记录
        insertReceipt(hotelOrder, currentUser.getId(), nowLocalDateTime);
        // 生成供应预订单
        HotelProductInfoDTO hotelProductInfoDTO = hotelProductService.selectInfo(hotelOrder.getHotelProductId());
        SupplierOrderSystemAirExpressAddReq supplierOrderSystemAirExpressAddReq = new SupplierOrderSystemAirExpressAddReq();
        supplierOrderSystemAirExpressAddReq.setBusinessType(SystemBusinessType.AIR_EXPRESS.getCode());
        supplierOrderSystemAirExpressAddReq.setProductType(ProductType.API_PRODUCT.getCode());
        supplierOrderSystemAirExpressAddReq.setDepartmentId(userDTO.getDeptId());
        supplierOrderSystemAirExpressAddReq.setDepartment(sysDepartmentDTO.getTitle());
        supplierOrderSystemAirExpressAddReq.setTotalFee(hotelOrder.getOrderAmount());
        supplierOrderSystemAirExpressAddReq.setPayableAmount(hotelOrder.getReceivableAmount());
        supplierOrderSystemAirExpressAddReq.setSaleNumber(hotelOrder.getOrderNumber());
        supplierOrderSystemAirExpressAddReq.setProductNumber(hotelProductInfoDTO.getProductCode());
        supplierOrderSystemAirExpressAddReq.setProductName(hotelProductInfoDTO.getName());
        supplierOrderSystemAirExpressAddReq.setSupplierId(hotelProductInfoDTO.getSupplierId());
        supplierOrderSystemAirExpressAddReq.setSupplierName(hotelProductInfoDTO.getSupplierName());
        supplierOrderService.addSystemAirExpress(supplierOrderSystemAirExpressAddReq, currentUser.getId());
        //保存订单,生成查询单号
        String inquiryNumber = generatorInquiryNumber();
        hotelOrder.setPaymentStatus(OrderPaymentStatus.ALREADY_PAYMENT.getCode());
        hotelOrder.setScheduledStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        //hotelOrderTouristMapper.insertBatchSomeColumn(airportExpressOrderTouristList);
        hotelOrderCollectionMapper.insertBatchSomeColumn(hotelOrderCollectionList);
        hotelOrderMapper.updateById(hotelOrder);
        return Result.success(id);
    }

    @Override
    public Result<List<MyHotelOrderDTO>> recentToNow(LocalDateTime recent, LocalDateTime now) {
        List<HotelOrder> orderList = baseMapper.selectList(Wrappers.<HotelOrder>lambdaQuery()
                .eq(HotelOrder::getIsDeleted,IsDeletedCode.NO.getCode())
                .ge(recent != null,HotelOrder::getGmtModified, recent)
                .le(HotelOrder::getGmtModified, now));
        List<Long> hotelIdList = new ArrayList<>();
        List<MyHotelOrderDTO> result = new ArrayList<>();
        for (HotelOrder hotelOrder : orderList) {
            MyHotelOrderDTO orderDTO = EntityUtil.copy(hotelOrder, MyHotelOrderDTO.class);
            /*HotelListDTO hotelListDTO = hotelService.queryDetail(hotelOrder.getHotelId());
            hotelListDTO = Optional.ofNullable(hotelListDTO).orElseGet(HotelListDTO::new);
            orderDTO.setHotelEnName(hotelListDTO.getEnName());
            orderDTO.setHotelName(hotelListDTO.getName());*/
            result.add(orderDTO);
            hotelIdList.add(hotelOrder.getHotelId());
        }

        if(!CollectionUtils.isEmpty(result)) {
            List<HotelListDTO> hotelListDTOS = hotelService.queryDetailList(hotelIdList);
            Map<Long, HotelListDTO> collect = hotelListDTOS.stream().collect(Collectors.toMap(HotelListDTO::getId, Function.identity()));
            for (MyHotelOrderDTO orderDTO : result) {
                HotelListDTO hotelListDTO = collect.get(orderDTO.getHotelId());
                if(hotelListDTO != null) {
                    orderDTO.setHotelEnName(hotelListDTO.getEnName());
                    orderDTO.setHotelName(hotelListDTO.getName());
                }
            }
        }
        return Result.success(result);
    }

    @Override
    public List<HotelOrderDTO> queryOrderDTOList(LocalDateTime start, LocalDateTime end) {
        return EntityUtil.copyList(baseMapper.selectList(Wrappers.<HotelOrder>lambdaQuery()
                .eq(HotelOrder::getIsDeleted, IsDeletedCode.NO.getCode())
                .ge(HotelOrder::getGmtCreate, start)
                .le(HotelOrder::getGmtCreate, end)),HotelOrderDTO.class);
    }

    private int insertReceipt(HotelOrder hotelOrder, Long userId, LocalDateTime nowLocalDateTime) {
        UserDTO userDTO = sysUserService.loadUserByParam(userId, 1);
        SysDepartmentDTO sysDepartmentDTO = sysDepartmentService.queryOne(userDTO.getDeptId());
        //生成收据单号
        String receiptNumber = generatorReceiptNumber(userDTO, sysDepartmentDTO, nowLocalDateTime);
        HotelOrderReceipt hotelOrderReceipt = new HotelOrderReceipt();
        hotelOrderReceipt.setId(SnowflakeIdWorker.nextId());
        hotelOrderReceipt.setOrderId(hotelOrder.getId());
        hotelOrderReceipt.setReceiptNo(receiptNumber);
        hotelOrderReceipt.setRoomNumber(null);//房单号码 暂时置空
        hotelOrderReceipt.setBranch(sysDepartmentDTO.getTitle());
        hotelOrderReceipt.setGuest(hotelOrder.getContactName());
        hotelOrderReceipt.setPhone(hotelOrder.getContactMobileAreaCode() + "-" + hotelOrder.getContactMobile());
        hotelOrderReceipt.setIsDeleted(IsDeletedCode.NO.getCode());
        hotelOrderReceipt.setCreateId(userId);
        hotelOrderReceipt.setGmtCreate(nowLocalDateTime);
        hotelOrderReceipt.setModifiedId(userId);
        hotelOrderReceipt.setGmtModified(nowLocalDateTime);
        return hotelOrderReceiptMapper.insert(hotelOrderReceipt);
    }

    /**
     * 生成收據號碼：門市編號+員工編號+年後2位+月日4位+B+時分秒6位+（S），
     * 例如：XS-C07884-200407-B-110008（S）
     *
     * @param userDTO
     * @return
     */
    private String generatorReceiptNumber(UserDTO userDTO, SysDepartmentDTO sysDepartmentDTO, LocalDateTime nowLocalDateTime) {
        String symbol = "-";
        String employeeNumber = userDTO.getEmployeeNumber();
        String deptCode = sysDepartmentDTO.getDeptCode();
        String yearCode = String.valueOf(nowLocalDateTime.getYear()).substring(2, 4);
        String monthCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMonthValue()), 2, "0");
        String dayCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getDayOfMonth()), 2, "0");
        String hourCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getHour()), 2, "0");
        String minuteCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMinute()), 2, "0");
        String secondCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getSecond()), 2, "0");
        StringBuilder receiptNumberSb = new StringBuilder();
        receiptNumberSb.append("XS").append(symbol).append(deptCode).append(symbol)
                .append(employeeNumber).append(symbol)
                .append(yearCode).append(symbol)
                .append(monthCode).append(symbol)
                .append(dayCode).append(symbol).append("-B-")
                .append(hourCode).append(symbol)
                .append(minuteCode).append(symbol)
                .append(secondCode).append(symbol)
                .append("（S）");
        return receiptNumberSb.toString();
    }

    /**
     * 生成查询号码，六位随机数字字符串
     *
     * @return
     */
    private String generatorInquiryNumber() {
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
        return randomNumber;
    }

    /**
     * 校验支付金额是否小于应收金额
     *
     * @param amountCountHKD   支付金额
     * @param receivableAmount 应收价格
     */
    private void checkAmount(BigDecimal amountCountHKD, BigDecimal receivableAmount) {
        if (amountCountHKD.compareTo(receivableAmount) < 0) {
            // 支付价格小于应收价格
            throw new BusinessException(SystemError.HOTEL_10080);
        }
    }

    /**
     * 生成收款单号:
     * SKD+年後2位+月日4位+時分秒6位+2位隨機數字
     */
    private String generatorPaymentNumber(LocalDateTime nowLocalDateTime) {
        String yearCode = String.valueOf(nowLocalDateTime.getYear()).substring(2, 4);
        String monthCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMonthValue()), 2, "0");
        String dayCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getDayOfMonth()), 2, "0");
        String hourCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getHour()), 2, "0");
        String minuteCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMinute()), 2, "0");
        String secondCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getSecond()), 2, "0");
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 10));
        StringBuilder orderNumberSb = new StringBuilder();
        orderNumberSb.append("SKD").append(yearCode).append(monthCode).append(dayCode).append(hourCode)
                .append(minuteCode).append(secondCode).append(randomNumber);
        return orderNumberSb.toString();
    }

    /**
     * 获取银联优惠金额
     *
     * @param hotelOrder
     * @param collection
     * @param user
     * @return
     */
    private void useAmountByBankReference(HotelOrder hotelOrder, HotelOrderCollection collection, TokenUser user) {
        OperateBankConformQueryReq operateBankConformQueryReq = new OperateBankConformQueryReq();
        operateBankConformQueryReq.setId(collection.getUnionpayDiscountId());//银联优惠ID
        operateBankConformQueryReq.setCardNumber(collection.getPayer());//卡号
        operateBankConformQueryReq.setTotalPaidIn(hotelOrder.getOrderAmount());//订单金额
        operateBankConformQueryReq.setBusinessType(SystemBusinessType.AIR_EXPRESS.getCode());
        operateBankConformQueryReq.setRelationId(hotelOrder.getHotelProductId());//订单ID
        operateBankConformQueryReq.setChannelId(OrderSource.CPM.getCode().longValue());//订单来源
        operateBankConformQueryReq.setUserId(user.getId());
//        operateBankConformQueryReq.setDiscountObjectId();//会员类型
        Result<OperateBankPreferenceQueryDTO> operateBankPreferenceQueryDTOResult = operateBankPreferenceService.queryConform(operateBankConformQueryReq);
        if (!operateBankPreferenceQueryDTOResult.isSuccess()) {
            // 校验银行优惠不满足条件
            SystemError defined = SystemError.getDefined(operateBankPreferenceQueryDTOResult.getCode());
            throw new BusinessException(defined);
        }
        OperateBankPreferenceQueryDTO bankQueryDto = operateBankPreferenceQueryDTOResult.getData();
        if (bankQueryDto.getDiscountType() == 1) {
            // 使用满额折扣优惠
            // 校验应收价格是否符合满减优惠
            if (hotelOrder.getReceivableAmount().compareTo(bankQueryDto.getFullAmount()) == -1) {
                // 校验银行优惠不满足条件
                throw new BusinessException(SystemError.AIREXPRESS_ORDER_60018);
            }
            collection.setCollectionAmount(bankQueryDto.getReductionAmount());
        } else {
            // 使用百分比优惠
            BigDecimal currentAmount = hotelOrder.getReceivableAmount().multiply(new BigDecimal(String.valueOf(bankQueryDto.getDiscountPercent())));
            currentAmount = currentAmount.compareTo(bankQueryDto.getMaxDiscount()) > 0 ? bankQueryDto.getMaxDiscount() : currentAmount;
            collection.setCollectionAmount(currentAmount);
        }
        /**
         * 扣减银联优惠
         */
        OperateBankDeductReq deductReq = new OperateBankDeductReq();
        deductReq.setId(collection.getUnionpayDiscountId());//银联优惠ID
        deductReq.setCardNumber(collection.getPayer());//卡号
        deductReq.setTotalPaidIn(hotelOrder.getOrderAmount());//订单金额
        deductReq.setBusinessType(SystemBusinessType.AIR_EXPRESS.getCode());
        deductReq.setRelationId(hotelOrder.getHotelProductId());//订单ID
        deductReq.setChannelId(OrderSource.CPM.getCode().longValue());//订单来源
        Result deductResult = operateBankPreferenceService.deduct(deductReq, user);
        if (!deductResult.isSuccess()) {
            // 校验银行优惠不满足条件
            SystemError defined = SystemError.getDefined(deductResult.getCode());
            throw new BusinessException(defined);
        }
    }

    /**
     * 生成机场快线销售编号=J+部门代码+员工编号+年后2位+月日4位+3位随机数字
     *
     * @param userId
     * @return
     */
    private String generatorOrderNumber(Long userId, LocalDateTime nowLocalDateTime) {
        UserDTO userDTO = sysUserService.loadUserByParam(userId, 1);
        String employeeNumber = userDTO.getEmployeeNumber();
        SysDepartmentDTO sysDepartmentDTO = sysDepartmentService.queryOne(userDTO.getDeptId());
        String deptCode = sysDepartmentDTO.getDeptCode();
        String yearCode = String.valueOf(nowLocalDateTime.getYear()).substring(2, 4);
        String monthCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMonthValue()), 2, "0");
        String dayCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getDayOfMonth()), 2, "0");
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 100));
        StringBuilder orderNumberSb = new StringBuilder();
        orderNumberSb.append("J").append(deptCode).append(employeeNumber).append(yearCode).append(monthCode).append(dayCode).append(randomNumber);
        return orderNumberSb.toString();
    }
    /**
     * 根据总价计算应收价格，减去会员积分和优惠券
     *
     * @param hotelOrder
     * @param orderAmount
     * @return 应收金额
     */
    private BigDecimal buildReceivableAmount(HotelOrder hotelOrder, BigDecimal orderAmount) {
        BigDecimal receivableAmount = new BigDecimal(orderAmount.toString());
        //计算应收价格-是否使用积分
        if (hotelOrder.getMemberQueryType() != null && hotelOrder.getUsingPoints() != null) {
            if (hotelOrder.getUsingPoints() <= 0) {
                //抵扣积分必须大于0;
                throw new BusinessException(SystemError.HOTEL_10074);
            }
            BigDecimal usingPoints = new BigDecimal(String.valueOf(hotelOrder.getUsingPoints()));
            // 校验会员积分是否充足
            checkMemberPoints(hotelOrder, usingPoints);
            //计算应收价格-计算积分
            BigDecimal usingPointsCNY = usingPoints.divide(Constants.POINTS_TO_CNY, 2, BigDecimal.ROUND_HALF_UP);
            //人民币兑港币
            MainDataCurrencyListDTO exchangeRateByName = getExchangeRateByName(Currency.CNY.getSymbol());
            BigDecimal crmExchangeRate = exchangeRateByName.getCrmExchangeRate();
            BigDecimal usingPointsHKD = usingPointsCNY.multiply(crmExchangeRate);
            receivableAmount = receivableAmount.subtract(usingPointsHKD);
            if (receivableAmount.compareTo(BigDecimal.ZERO) == -1) {
                // 总价减去积分价后为负数，不予许提交
                throw new BusinessException(SystemError.AIREXPRESS_ORDER_60007);
            }
        }
        //计算应收价格-计算推广码（优惠券）, 机场快线没有推广码业务
        if (hotelOrder.getCouponId() != null) {
            // do something 推广码接口未写完，等待中
            /*OperatePromotionConformReq operatePromotionConformReq = new OperatePromotionConformReq();
            operatePromotionConformReq.setActivityCode(airportExpressOrder.getCouponId().toString());
            operatePromotionConformReq.setTotalPaidIn(airportExpressOrder.getOrderAmount());
            operatePromotionConformReq.setBusinessType(SystemBusinessType.AIR_EXPRESS.getCode());
            operatePromotionConformReq.setRelationId(airportExpressOrder.getAirportExpressId());
            operatePromotionConformReq.setChannelId(airportExpressOrder.getSource().longValue());
            operatePromotionConformReq.setUserId(airportExpressOrder.getModifiedId());
            Result<OperatePromotionQueryDTO> operatePromotionQueryDTOResult = operatePromotionService.queryConform(operatePromotionConformReq);
            if (operatePromotionQueryDTOResult.getCode() != 0) {
                //该订单不满足使用条件
                SystemError systemError = SystemError.getDefined(operatePromotionQueryDTOResult.getCode());
                throw new BusinessException(systemError);
            }
            OperatePromotionQueryDTO data = operatePromotionQueryDTOResult.getData();
            receivableAmount = receivableAmount.subtract(data.getReductionAmount());
            if (receivableAmount.compareTo(BigDecimal.ZERO) == -1) {
                // 总价减去积分价后为负数，不予许提交
                throw new BusinessException(SystemError.AIREXPRESS_ORDER_60007);
            }*/
        }
        return receivableAmount;
    }

    /**
     * 校验积分是否充足
     *
     * @param hotelOrder
     * @param usingPoints
     */
    private void checkMemberPoints(HotelOrder hotelOrder, BigDecimal usingPoints) {
        ContactQueryDTO contactQuery;
        try {
            CrmMemberQueryReq crmMemberQueryReq = new CrmMemberQueryReq(hotelOrder.getMemberQueryType(), hotelOrder.getMemberQueryCode(), hotelOrder.getMemberQueryCertificatesType().toString());
            contactQuery = crmMemberService.queryMember(crmMemberQueryReq);
        } catch (Exception e) {
            if (e instanceof BusinessException) {
                throw e;
            } else {
                throw new BusinessException(SystemError.HOTEL_10075);
            }
        }
        BigDecimal findMemberPoints = new BigDecimal(String.valueOf(contactQuery.getMember().getPoint1Value()));
        if (findMemberPoints.compareTo(usingPoints) < 0) {
            // 会员积分不足
            throw new BusinessException(SystemError.HOTEL_10076);
        }
    }

    /**
     * 根据币种名称获取汇率
     *
     * @param currencySy
     * @return
     */
    private MainDataCurrencyListDTO getExchangeRateByName(String currencySy) {
        MainDataCurrencyListReq mainDataCurrencyListReq = new MainDataCurrencyListReq();
        mainDataCurrencyListReq.setName(currencySy);
        PageResponse<MainDataCurrencyListDTO> list = mainDataCurrencyService.list(mainDataCurrencyListReq);
        if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(list.getRecords())) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60003);
        }
        return list.getRecords().get(0);
    }

    /**
     * 根据币种ID获取汇率，获取汇率,
     *
     * @return
     */
    private MainDataCurrencyQueryDTO getExchangeRateByName(Long currencyId) {
        MainDataCurrencyUpdateStatusReq mainDataCurrencyUpdateStatusReq = new MainDataCurrencyUpdateStatusReq();
        mainDataCurrencyUpdateStatusReq.setId(currencyId);
        Result<MainDataCurrencyQueryDTO> queryCurrencyRateResult = mainDataCurrencyService.query(mainDataCurrencyUpdateStatusReq);
        if (!queryCurrencyRateResult.isSuccess()) {
            SystemError defined = SystemError.getDefined(queryCurrencyRateResult.getCode());
            throw new BusinessException(defined);
        }
        return queryCurrencyRateResult.getData();
    }

    /**
     * 填写订单信息下单
     * @param hotelPlaceOrderReq
     * @param user
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result addHotelOrder(HotelPlaceOrderReq hotelPlaceOrderReq, TokenUser user) {

        if(Objects.isNull(hotelPlaceOrderReq)){
            return Result.failed(SystemError.HOTEL_10028);
        }

        List<HotelOrderTouristReq> touristReqList = hotelPlaceOrderReq.getHotelOrderTouristReqList();

        if(CollectionUtils.isEmpty(touristReqList)){
            return Result.failed(SystemError.HOTEL_10029);
        }

        //添加订单信息
        HotelOrder hotelOrder = new HotelOrder();
        BeanUtils.copyProperties(hotelPlaceOrderReq,hotelOrder);
        Long orderId = SnowflakeIdWorker.nextId();
        hotelOrder.setId(orderId);


        // 服务个数&单张服务费
        Integer num = hotelPlaceOrderReq.getServiceNum();
        BigDecimal fee = hotelPlaceOrderReq.getFee();
        // 总服务费
        BigDecimal decimal = BigDecimal.ZERO;
        if(null != num && null != fee){
            decimal = fee.multiply(BigDecimal.valueOf(num));
        }
        // 房间总数量&单间房的价格
        Integer ticketNum = hotelPlaceOrderReq.getNumber();
        BigDecimal singleTicketFee = hotelPlaceOrderReq.getSingleTicketFee();
        BigDecimal multiply = singleTicketFee.multiply(BigDecimal.valueOf(ticketNum));

        // 积分费用
        BigDecimal integralFee = hotelPlaceOrderReq.getIntegralDeduction();
        // 推广码优惠券费用
        BigDecimal couponDeduction = hotelPlaceOrderReq.getCouponDeduction();

        // 酒店总价格(加上服务费)
        BigDecimal ticketFee = decimal.add(multiply);

        BigDecimal orderFee = ticketFee;

        if(!Objects.isNull(integralFee)){
            orderFee = ticketFee.subtract(integralFee);
        }

        if(!Objects.isNull(couponDeduction)){
            orderFee = orderFee.subtract(couponDeduction);
        }

        // 订单总额
        hotelOrder.setOrderAmount(orderFee);
        hotelOrder.setCreateId(user.getId());
        hotelOrder.setGmtCreate(LocalDateTime.now());
        hotelOrderMapper.insert(hotelOrder);


        //添加订单旅客信息
        for(HotelOrderTouristReq hotelOrderTouristReq : touristReqList){
            HotelOrderTourist hotelOrderTourist = new HotelOrderTourist();
            BeanUtils.copyProperties(hotelOrderTouristReq,hotelOrderTourist);
            hotelOrderTourist.setId(SnowflakeIdWorker.nextId());
            hotelOrderTourist.setOrderId(orderId);
            hotelOrderTourist.setCreateId(user.getId());
            hotelOrderTourist.setGmtCreate(LocalDateTime.now());
            hotelOrderTouristMapper.insert(hotelOrderTourist);
        }
        return Result.success();
    }

    /**
     * 积分兑换港币 ￥
     *
     * @param integral 积分
     * @return 返回值
     */
    @Override
    public Result<HotelOrderIntegralExchangeDTO> conversionIntegral(Long integral) {
        HotelOrderIntegralExchangeDTO scenicOrderIntegralExchangeDTO = new HotelOrderIntegralExchangeDTO();

        MainDataCurrencyListReq mainDataCurrencyListReq = new MainDataCurrencyListReq();
        mainDataCurrencyListReq.setName("CNY");
        PageResponse<MainDataCurrencyListDTO> list = iMainDataCurrencyService.list(mainDataCurrencyListReq);
        List<MainDataCurrencyListDTO> records = list.getRecords();
        if(com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(records)){
            // 人民币id
            Long id = records.get(0).getId();
            MainDataCurrencyUpdateStatusReq currencyUpdateStatusReq = new MainDataCurrencyUpdateStatusReq();
            currencyUpdateStatusReq.setId(id);
            Result<MainDataCurrencyQueryDTO> queryDTOResult = iMainDataCurrencyService.query(currencyUpdateStatusReq);
            MainDataCurrencyQueryDTO result = queryDTOResult.getData();
            if(null != result){
                // 人民币兑换港币汇率
                BigDecimal crmExchangeRate = result.getCrmExchangeRate();
                // 积分
                Integer integralNum = Integer.valueOf(integral.toString());
                // 积分兑换人民币
                Integer var = integralNum/100;
                BigDecimal money = crmExchangeRate.multiply(BigDecimal.valueOf(var));

                scenicOrderIntegralExchangeDTO.setIntegral(integral);
                scenicOrderIntegralExchangeDTO.setIntegralDeduction(money);
                return Result.success(scenicOrderIntegralExchangeDTO);
            }
        }
        return null;
    }

    /**
     * 根据订单id查询订单信息
     *
     * @param orderId 订单id
     * @return 订单消息
     */
    @Override
    public Result<HotelOrderPayQueryInfoDTO> queryOrderInfo(Long orderId) {
        try {
            HotelOrder scenicOrder = hotelOrderMapper.selectById(orderId);
            if (null == scenicOrder){
                throw new BusinessException(SystemError.SYS_411);
            }
            // 应收总额
            BigDecimal orderAmount = scenicOrder.getOrderAmount();
            LocalDateTime time = scenicOrder.getGmtCreate();
            LocalDateTime payDueTime = time.plusMinutes(30);
            HotelOrderPayQueryInfoDTO payOrderDTO = new HotelOrderPayQueryInfoDTO();
            payOrderDTO.setOrderAmount(orderAmount);
            payOrderDTO.setPayDueTime(payDueTime);
            return Result.success(payOrderDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.failed(new BusinessException(SystemError.SYS_500));
    }

    /**
     * 预订中心下单
     *
     * @param reqList 预订中心订单入参
     * @return 返回值
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result payOrder(List<HotelPayOrderCollectionReq> reqList, Long userId) {
        if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(reqList)) {
            throw new BusinessException(SystemError.SYS_416);
        }
        // 每个收款明细对象的  总应收与订单id 相同
        HotelPayOrderCollectionReq collectionReq = reqList.get(0);
        // 总应收
        BigDecimal countAmount = collectionReq.getCountAmount();
        // 订单id
        Long orderId = collectionReq.getOrderId();

        BigDecimal money = BigDecimal.ZERO;

        for (HotelPayOrderCollectionReq orderCollectionReq : reqList) {
            // 收款币种id
            Long currencyId = orderCollectionReq.getCurrencyId();
            // 收款金额
            BigDecimal collectionAmount = orderCollectionReq.getCollectionAmount();

            MainDataCurrencyUpdateStatusReq currencyUpdateStatusReq = new MainDataCurrencyUpdateStatusReq();
            currencyUpdateStatusReq.setId(currencyId);
            Result<MainDataCurrencyQueryDTO> queryDTOResult = iMainDataCurrencyService.query(currencyUpdateStatusReq);
            MainDataCurrencyQueryDTO result = queryDTOResult.getData();
            if (null != result) {
                // 汇率
                BigDecimal crmExchangeRate = result.getCrmExchangeRate();
                // 收款金额换算汇率后金额
                BigDecimal multiply = collectionAmount.multiply(crmExchangeRate);
                money = money.add(multiply);
            }
        }
        // 总应收与输入总金额应一致
        if (countAmount.setScale(0, BigDecimal.ROUND_HALF_UP).compareTo(money.setScale(0, BigDecimal.ROUND_HALF_UP)) != 0) {
            throw new BusinessException(SystemError.BUS_ORDER_9004);
        }

        HotelOrderCollection hotelOrderCollection;
        for (HotelPayOrderCollectionReq orderCollectionReq : reqList) {
            hotelOrderCollection = EntityUtil.copy(orderCollectionReq, HotelOrderCollection.class);
            hotelOrderCollection.setId(SnowflakeIdWorker.nextId());
            hotelOrderCollection.setOrderId(orderId);
            hotelOrderCollection.setCreateId(userId);
            String collectionCertificate = orderCollectionReq.getCollectionCertificateJson();
            if(StringUtils.isNotEmpty(collectionCertificate)){
                String collectionCertificateJson = JSON.toJSONString(collectionCertificate);
                hotelOrderCollection.setCollectionCertificateJson(collectionCertificateJson);
            }
            hotelOrderCollectionMapper.insert(hotelOrderCollection);
        }
        return Result.success();
    }

    @Override
    public PageResponse<HotelOrderPageDTO> queyList(HotelOrderPageReq hotelOrderPageReq) {
        return null;
    }

    /**
     * 根据订单id查询订单详细信息
     *
     * @param orderId 订单id
     * @return 订单消息
     */
    @Override
    public Result<HotelOrderDetailDTO> queryOrderDetailInfo(Long orderId) {
        //根据订单id查询订单信息
        HotelOrder hotelOrder = hotelOrderMapper.selectById(orderId);
        if(Objects.isNull(hotelOrder)){
            return Result.failed(SystemError.HOTEL_10031);
        }
        HotelOrderDetailDTO hotelOrderDetailDTO =  EntityUtil.copy(hotelOrder,HotelOrderDetailDTO.class);

        //酒店外挂单
        HotelManualOrder hotelManualOrder = hotelManualOrderMapper.selectOne(new QueryWrapper<HotelManualOrder>().lambda().eq(HotelManualOrder::getOrderId, orderId));
        if(!Objects.isNull(hotelManualOrder)){
            HotelManualOrderDetailDTO hotelManualOrderDetailDTO =  EntityUtil.copy(hotelManualOrder,HotelManualOrderDetailDTO.class);
            hotelOrderDetailDTO.setHotelManualOrderDetailDTO(hotelManualOrderDetailDTO);
        }

        //酒店订单旅客信息
        List<HotelOrderTourist> hotelOrderTouristList = hotelOrderTouristMapper.selectList(new QueryWrapper<HotelOrderTourist>().lambda().eq(HotelOrderTourist::getOrderId, orderId));
        if(!CollectionUtils.isEmpty(hotelOrderTouristList)){
            List<HotelOrderTouristDTO> busOrderTouristDTOList =  EntityUtil.copyList(hotelOrderTouristList,HotelOrderTouristDTO.class);
            hotelOrderDetailDTO.setHotelOrderTouristDTOList(busOrderTouristDTOList);
        }

        //酒店收款明细信息
        List<HotelOrderCollection> hotelOrderCollectionList = hotelOrderCollectionMapper.selectList(new QueryWrapper<HotelOrderCollection>().lambda().eq(HotelOrderCollection::getOrderId, orderId));
        if(!CollectionUtils.isEmpty(hotelOrderCollectionList)){
            List<HotelOrderCollectionDTO> busOrderCollectionDTOList =  EntityUtil.copyList(hotelOrderCollectionList,HotelOrderCollectionDTO.class);
            hotelOrderDetailDTO.setHotelOrderCollectionDTOList(busOrderCollectionDTOList);
        }

        //酒店退款明细信息
        List<HotelOrderRefund> hotelOrderRefundList = hotelOrderRefundMapper.selectList(new QueryWrapper<HotelOrderRefund>().lambda().eq(HotelOrderRefund::getOrderId, orderId));
        if(!CollectionUtils.isEmpty(hotelOrderRefundList)){
            List<HotelOrderRefundDTO> busOrderRefundDTOList =  EntityUtil.copyList(hotelOrderRefundList,HotelOrderRefundDTO.class);
            hotelOrderDetailDTO.setHotelOrderRefundDTO(busOrderRefundDTOList);
        }

        return Result.success(hotelOrderDetailDTO);
    }

    /**
     * 修改旅客信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result updateHotelOrderTourist(HotelOrderTouristReq touristReq, Long userId) {

        HotelOrderTourist hotelOrderTourist = hotelOrderTouristMapper.selectById(touristReq.getId());
        if(Objects.isNull(hotelOrderTourist)){
            return Result.failed(SystemError.HOTEL_10032);
        }
        hotelOrderTourist =  EntityUtil.copy(touristReq, HotelOrderTourist.class);
        hotelOrderTourist.setModifiedId(userId);
        hotelOrderTourist.setGmtModified(LocalDateTime.now());
        hotelOrderTouristMapper.updateById(hotelOrderTourist);
        return Result.success();
    }

    /**
     * 取消订单
     * @param cancelOrderReq
     * @param userId
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result cancelOrder(HotelCancelOrderReq cancelOrderReq, Long userId) {
        //根据订单id查询订单信息
        HotelOrder busOrder = hotelOrderMapper.selectById(cancelOrderReq.getOrderId());
        if(Objects.isNull(busOrder)){
            return Result.failed(SystemError.HOTEL_10031);
        }
        busOrder.setCancelStatus(1);
        busOrder.setGmtModified(LocalDateTime.now());
        busOrder.setModifiedId(userId);
        hotelOrderMapper.updateById(busOrder);
        return Result.success();
    }
}
